package org.cfx.basic.service.impl;

import org.cfx.basic.mapper.BaseMapper;
import org.cfx.basic.query.BaseQuery;
import org.cfx.basic.service.IBaseService;
import org.cfx.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public void add(T employee) {
        baseMapper.add(employee);
    }

    @Override
    public void update(T employee) {
        baseMapper.update(employee);
    }

    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public T queryById(Long id) {
        return baseMapper.queryById(id);
    }

    @Override
    public List<T> queryAll() {
        return baseMapper.queryAll();
    }

    @Override
    public PageList<T> queryAllPage(BaseQuery baseQuery) {
        Long count = baseMapper.queryCount(baseQuery);
        if (count == 0) {
            return new PageList<>();
        }else {
            List<T> employees = baseMapper.queryAllPage(baseQuery);
            return new PageList<>(count,employees);
        }
    }

    @Override
    public List<T> query() {
        return baseMapper.query();
    }

    @Override
    public List<T> queryManager() {
        return baseMapper.queryManager();
    }

    @Override
    public void batchRemove(List<Long> ids) {
        baseMapper.batchRemove(ids);
    }
}
